package com.xywy.bloodandroid.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xywy.bloodandroid.R;
import com.xywy.bloodandroid.act.QuestionDetailAct;
import com.xywy.bloodandroid.act.QuestionDetailAct_Two;
import com.xywy.bloodandroid.base.BasicAdapter;
import com.xywy.bloodandroid.bean.QuestionList;

public class DoctorListAdapter extends BasicAdapter<QuestionList> {
	private LayoutInflater inflater;
	private String state;
	public DoctorListAdapter(Context context, List<QuestionList> list) {
		super(context, list);
		this.inflater = LayoutInflater.from(context);
	}
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
    	 viewholder holder;
    	 if(convertView==null){
    		 holder=new viewholder();
    		 convertView=inflater.inflate(R.layout.item_question_list, null);
    		 holder.replaied=(TextView) convertView.findViewById(R.id.replaied);
    		 holder.title=(TextView) convertView.findViewById(R.id.title);
    		 holder.data=(TextView) convertView.findViewById(R.id.data);
    		 convertView.setTag(holder);
    	 }else{
    		 holder=(viewholder) convertView.getTag();
    	 }
    	 
    	 String shortmsg=list.get(position).getShortmsg();
    	 String title=list.get(position).getTitle();
    	 String  realname=  list.get(position).getRealname();
    	 String createtime= list.get(position).getCreatetime();
    	  state = "-2";
    	 if(shortmsg.length()>0){
    		 holder.replaied.setVisibility(View.VISIBLE);
    		 state="-1";
    	 }else{
    		 holder.replaied.setVisibility(View.GONE);
    		 state="0";
    	 }
    	 holder.title.setText(title);
    	 holder.data.setText(realname+"发表于"+createtime);
    	 
    	 convertView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
			Intent intent=new Intent(context, QuestionDetailAct_Two.class);
			intent.putExtra("state", state);
			intent.putExtra("art_id", list.get(position).getArt_id());
			context.startActivity(intent);
				
			}
		});
    	
    	return convertView;
    }
    
    private class viewholder{
    	private TextView replaied;
    	private TextView title;
    	private TextView data;
    }
}
